#include <string>
#include <cctype>
#include <iostream>

using namespace std;

class Solution {
public:
    bool isPalindrome(string s) {
        auto begin = s.begin(); 
        auto end = s.end() - 1;
        for (int i = 0; i < s.size(); i++){
            if (isupper(s[i])){
                s[i] = s[i] - 'A' + 'a';
            }
        }
        while (begin != end){
            while (begin != end && !isalnum(*begin)){
                begin++;
            }
            while (begin != end && !isalnum(*end)){
                end--;
            }
            if (*begin != *end){
                return false;
            }
            if (end == begin){
                break;
            }
            begin++;
            if (end == begin){
                break;
            }
            end--;
        }
        return true;
    }
};


